package dao

import (
	"fmt"
	"go_web/models"
	"log"
)

func GetUserNameByID(userId int) string {

	row := DB.QueryRow("select user_name from blog_user where uid=?", userId)
	if row.Err() != nil {
		log.Println(row.Err())
	}

	var userName string
	row.Scan(&userName)

	return userName
}

func GetUser(userName, passwd string) *models.User {
	row := DB.QueryRow("select * from blog_user where user_name=? and passwd=? limit 1", userName, passwd)

	if row.Err() != nil {
		log.Println(row.Err())
		return nil
	}

	var user = &models.User{}

	_ = row.Scan(&user.Uid, &user.UserName, &user.Passwd, &user.Avatar, &user.CreatAt, &user.UpdateAt)
	fmt.Println(user)
	if user.UserName == "" {
		log.Println("用户名查询出错")
		return nil
	}
	return user
}
